import com.qian.api.ddj.model.QueryModel;
import com.qian.api.ddj.model.WitthdrawReturn;
import lombok.Data;
import org.junit.Test;
import org.springframework.util.StringUtils;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.TreeMap;

@Data
public class asd {
    private String a;
    private String b;
    private String c;
    private String d;

        @Test
        public void test11(){
            asd model = new asd();
            model.setA("1");
            model.setB("2");
            model.setC("");
            model.setD("4");
            getMap(model);
        }

    public Map getMap(Object object){
        Map<String,String> map = new TreeMap();
        Class modelClz = object.getClass();
        Field[] fs = modelClz.getDeclaredFields();
        for (int i=0;i<fs.length;i++){
            Field field = fs[i];

            field.setAccessible(true);

            Object val = null;
            try {
                val = field.get(object);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            if (!StringUtils.isEmpty(val)){
                map.put(field.getName(),val.toString());
            }

        }
        System.out.println(map);
        return map;
    }

    @Test
    public void reflex_test() throws IllegalAccessException {
        asd model = new asd();
        model.setA("1");
        model.setB("2");
        model.setC("3");
        model.setD("4");

        Class modelClz = model.getClass();

        Field[] fs = modelClz.getDeclaredFields();
        for (int i=0;i<fs.length;i++){
            Field field = fs[i];

            field.setAccessible(true);

            Object val = field.get(model);

            System.out.println("name:"+ field.getName());
            System.out.println("value:"+val);
        }

    }

    @Test
    public void a(){
        QueryModel model = new QueryModel();
        model.setUserId("123");
        b(model);
        System.out.println(model.getUserId());
        model.setUserId("789");
        System.out.println(model.getUserId());
    }

    public void b(QueryModel model){
        model.setUserId("456");
    }

    @Test
    public void aa() throws IllegalAccessException {
        WitthdrawReturn model = new WitthdrawReturn();
        model.setTypeInfo("1");
        model.setAmount("2");
        model.setOutOrderNo("12312312313");

        Class modelClz = model.getClass();

        Field[] fs = modelClz.getDeclaredFields();
        for (int i=0;i<fs.length;i++){
            Field field = fs[i];

            field.setAccessible(true);

            Object val = field.get(model);

            System.out.println("name:"+ field.getName());
            System.out.println("value:"+val);
        }
    }
}
